<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>档案维护</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/layer-css.css"/>
    <style>
        .organizationTree {
            width: 100% !important;
            height: -webkit-calc(100vh - 160px);
            height: -moz-calc(100vh - 160px);
            height: calc(100vh - 300px);

        }

        .centered {
            display: flex;
            flex-direction: row;
            align-items: center;
        }

        .separateInTheCenter {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
        }

        .pear-container {
            margin: 15px;
            width: calc(100vw - 30px);
        }

        body {
            font-family: Source Han Sans SC, Source Han Sans SC;
        }

        .searchCriteria .layui-form-label {
            width: 64px;
            font-size: 16px;
            color: #5A6878;
        }

        .searchCriteria button {
            line-height: 31px;
            font-size: 16px;
        }

        .searchCriteria .layui-icon {
            font-size: 15px;
        }

        .toolbarButton button {
            font-size: 16px;
            border: 0px;
            border-radius: 5px 5px 5px 5px;
        }

        .toolbarButton .layui-btn {
            margin-bottom: 0px;
        }

        .layui-table-box button {
            font-size: 14px !important;
            height: 25px;
            line-height: 23px;
        }

        #moreTools a {
            color: #1890FF;
            margin-left: 20px;
        }

        .layui-btn-container .layui-btn {
            margin-left: 15px !important;
            height: 40px;
            line-height: 40px;
        }

        .type-title {
            width: 140px;
            height: 46px;
            border-radius: 5px 0px 0px 0px;
            font-size: 18px;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
        }

        .type-title:hover {
            background: #FFFFFF;
            color: #398FFF !important;
        }

        .toolbarButton button {
            font-size: 16px;
            border: 0px;
            border-radius: 5px 5px 5px 5px;
        }
    </style>
</head>
<body class="pear-container">
<div class="layui-row layui-col-space15">
    <div class="layui-col-xs12 layui-col-md12">
        <div class="layui-card" style="display: flex;flex-direction: row;background: #f6f7fc;">
            <div class="type-title" style="background: #FFFFFF;" id="1">
                <a href="javascript:void(0);" style="color: #398FFF;">全部</a>
            </div>
            <div class="type-title" id="2">
                <a href="javascript:void(0);" style="color: #9CA7B7">借阅管理</a>
            </div>
            <div class="type-title" id="3">
                <a href="javascript:void(0);" style="color: #9CA7B7">统计</a>
            </div>
            <div class="type-title" id="5">
                <a href="javascript:void(0);" style="color: #9CA7B7">导入</a>
            </div>
        </div>
    </div>
</div>
<div class="archivesBody">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-xs12 layui-col-md12">
            <div class="layui-card searchCriteria">
                <div class="layui-card-body">
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">档案名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="fileName" placeholder="请输入档案名称" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label required">区域位置</label>
                                <div class="layui-input-inline">
                                    <input type="number" id="archiveArea" name="archiveArea"
                                           style="display:none;width: 0px" autocomplete="off" class="layui-input">
                                    <ul id="areaTree" class="dtree" data-id="0"></ul>
                                </div>
                            </div>
                            <div class="layui-form-item layui-inline">
                                <label class="layui-form-label">年度</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="year" class="layui-input" id="yearInput"
                                           placeholder="请选择年度">
                                </div>
                            </div>

                            <div class="layui-form-item layui-inline">
                                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
                                        lay-filter="search-query">
                                    <i class="layui-icon layui-icon-search"></i>
                                    查询
                                </button>
                                <button type="reset" class="pear-btn pear-btn-md" id="reset">
                                    <i class="layui-icon layui-icon-refresh"></i>
                                    重置
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-md12">
            <div class="layui-card toolbarButton">
                <div class="layui-card-body">
                    <div class="layui-btn-container centered" style="height: 65px">
                        <button class="layui-btn layui-btn-primary layui-border-green"
                                style="background-color: rgb(57, 143, 255, 0.1);color: #398FFF !important;"
                                lay-on="addArchives">添加档案
                        </button>
                        <button class="layui-btn layui-btn-primary layui-border-green"
                                style="background-color: rgb(255,146,0, 0.1);color: #FF9200 !important; "
                                lay-on="batchDelete">批量删除
                        </button>
                        <button class="layui-btn layui-btn-primary layui-border-green"
                                style="background-color: rgb(0 188 212 / 15%);color:#00BCD4 !important"
                                lay-on="scanningGun">扫描枪
                        </button>
                        <button class="layui-btn layui-btn-primary layui-border-green"
                                style="background-color: rgb(0 188 212 / 15%);color:#00BCD4 !important"
                                lay-on="batchPrintQRCode">批量打印二维码
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md2 layui-col-sm12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div id="organizationTreeContent" style="overflow: auto;">
                        <ul id="organizationTree" class="dtree organizationTree" data-id="9527"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md10" id="archives">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table id="archivesTable" lay-filter="archivesTable"></table>
                </div>
            </div>
        </div>
        <div class="layui-col-md10" style="display: none" id="borrowing">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table id="borrowingTable" lay-filter="borrowingTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="statisticsBody" style="display: none">
    <iframe src="/archives/statistics" style="margin-bottom: 0px" width="100%"
            name="ifd" id="myIframe"
            height="1000px" frameborder="0" scrolling="no"></iframe>
</div>


<script type="text/html" id="archivesTableBar">
    <!--    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="info">详情</button>-->
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit">修改</button>
    <!--    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="electronicArchives"-->
    <!--            style="background-color: #F3B013 !important;border: 1px solid #F3B013 !important;">电子档案-->
    <!--    </button>-->
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove">删除</button>
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="more">更多
        <i class="layui-icon layui-icon-down"></i></button>
</script>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script th:inline="javascript">
    var sysType = [[${sysType}]];
    layui.use(['table', 'form', 'jquery', 'common', 'laydate', 'dtree', 'util', 'dropdown'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        var laydate = layui.laydate;
        let dtree = layui.dtree;
        var util = layui.util;
        var dropdown = layui.dropdown;

        var addCollectionIdList = [];
        var checkTable = 1;

        laydate.render({
            elem: '#yearInput', //指定元素
            type: 'year',
            theme: '#333'
        });

        // 左侧展开区域树
        dtree.render({
            elem: "#organizationTree",
            initLevel: "2", //默认展开层级为1
            line: true, // 有线树
            ficon: ["1", "-1"], // 设定一级图标样式。0表示方形加减图标，8表示小圆点图标
            icon: ["0", "2"], // 设定二级图标样式。0表示文件夹图标，5表示叶子图标
            method: 'get',
            url: "/archives/area/buildAreaTree",
            height: "full-213"  // 设置高度，也可以直接固定数字
        });
        dtree.on("node('organizationTree')", function (obj) {
            areaId = obj.param.nodeId;
            areaName = obj.param.context;
            if (checkTable === 1) {
                table.reload("archivesTable", {
                    where: {
                        "areaId": areaId
                    }
                });
            } else if (checkTable === 2) {
                table.reload("borrowingTable", {
                    where: {
                        "areaId": areaId
                    }
                });
            }
        });

        // 复选框事件
        table.on('checkbox(archivesTable)', function (obj) {
            addCollectionIdList = common.checkField(obj, 'id');
            console.log(addCollectionIdList)
        });


        // dtree插件下拉框点击空白处隐藏
        $(document).bind("click", function (e) {
            var e = e || window.event;    //事件对象，兼容IE
            var target = e.target || e.srcElement;  //源对象，兼容火狐和IE
            if ($(target).prop("class").indexOf("layui-card") == -1) {
                $(".dtree-select-show").removeClass("dtree-select-show");
            }
        })
        // 初始化区域树
        dtree.render({
            elem: "#areaTree",
            initLevel: "1",//默认展开层级为1
            width: "100%",
            method: 'get',
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            // response:{message:"msg",statusCode:200},  //修改response中返回数据的定义
            url: "/archives/area/buildAreaTree/table",
            dataFormat: "list",  //配置data的风格为list
            select: true, //指定下拉树模式
            selectTips: "请选择区域位置",
            // selectCardHeight: "150"
        });
        dtree.on("node('areaTree')", function (obj) {
            var param = dtree.getNowParam("areaTree");
            $("#archiveArea").val(param.nodeId);
        });

        util.on({
            addArchives: function () {
                parent.layer.open({
                    title: ['新增档案', 'font-size: 18px;'],
                    type: 2,
                    offset: 'r',
                    anim: 'slideLeft', // 从右往左
                    area: ['40%', '100%'],
                    shade: 0.5,
                    maxmin: true,
                    id: 'addNewEquipment',
                    content: '/archives/insert/add',
                    move: false,
                    end: function () {
                        table.reload('archivesTable');
                    }
                });
            },
            batchDelete: function () {
                // 档案批量删除
                if (addCollectionIdList.length === 0) {
                    layer.msg("未选中数据", {
                        icon: 3,
                        time: 1000
                    });
                    return false;
                }
                layer.confirm('<div>确定要删除所选档案吗?</div>', {
                    icon: 3,
                    title: ['删除确认', 'font-size: 18px;'],
                    shade: 0.5,
                    area: ['499px', '303px'],
                    id: "borrowingConfirm"
                }, function (index) {
                    let loading = layer.load();
                    $.ajax({
                        url: "/archives/delete/save/" + addCollectionIdList,
                        dataType: 'json',
                        type: 'delete',
                        success: function (result) {
                            layer.close(loading);
                            if (result.code === 200) {
                                layer.msg(result.message, {
                                    icon: 1,
                                    time: 1800
                                }, function () {
                                    table.reload("archivesTable");
                                });
                            } else {
                                layer.msg(result.message, {
                                    icon: 2,
                                    time: 3000
                                });
                            }
                        }
                    })
                });
            },
            // 扫描枪
            scanningGun: function () {
                parent.layer.open({
                    title: ['扫码枪', 'font-size: 18px;'],
                    type: 2,
                    skin: 'layui-layer-radius', // 自定义一个CSS类名来设置边框圆角
                    area: [common.isModile() ? '100%' : '1000px', common.isModile() ? '100%' : '650px'],
                    shade: 0.5,
                    move: false,
                    content: '/archives/scanning/gun',
                    success: function (layero, index) {
                        // layer.full(index); // 最大化
                    }
                });
            },
            // 批量打印二维码
            batchPrintQRCode: function () {
                parent.layer.open({
                    title: ['打印二维码', 'font-size: 18px;'],
                    type: 2,
                    area: ['70%', '80%'],
                    shade: 0.5,
                    move: false,
                    maxmin: true, //开启最大化最小化按钮
                    content: '/archives/qrCode/table',
                    skin: 'layui-layer-radius', // 自定义一个CSS类名来设置边框圆角
                });
            }
        });

        $(".type-title").click(function () {
            $(this).siblings().css({"background": "#F6F7FC"});
            $(".type-title").find('a').css({"color": "#9CA7B7"});
            $(this).find('a').css({"color": "#398FFF"});
            $(this).css({"background": "#FFFFFF"});
            var type = $(this).attr("id");
            console.log(type)
            if (type === "1") {
                table.reload('archivesTable', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    }
                });
                $("#borrowing").css("display", "none")
                $("#archives").css("display", "")
                $(".archivesBody").css("display", "");
                $(".statisticsBody").css("display", "none");
                checkTable = 1;
            } else if (type === "2") {
                table.reload('borrowingTable', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    }
                });
                $("#borrowing").css("display", "")
                $("#archives").css("display", "none")
                $(".archivesBody").css("display", "");
                $(".statisticsBody").css("display", "none");
                checkTable = 2;
            } else if (type === "3") {
                $(".archivesBody").css("display", "none");
                $(".statisticsBody").css("display", "");
            } else if (type === "5") {
                parent.layer.open({
                    title: ['批量导入', 'font-size: 18px;'],
                    type: 2,
                    skin: 'layui-layer-radius', // 自定义一个CSS类名来设置边框圆角
                    area: ['70%', '80%'],
                    shade: 0.5,
                    shadeClose: false,
                    maxmin: true,
                    move: false,
                    id: 'collection',
                    content: '/archives/batchImport/view',
                });

            } else {
                $("#archiveStorage").css("display", "none");
                $("#notYetInStock").css("display", "");
                table.reload('notYetInStock-table', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    }
                });
                checkTable = 2;
            }
        })
        let cols = [
            [
                {type: 'checkbox'},
                {title: '档案id', field: 'file_id', align: 'center'},
                {title: '档案区域', field: 'area_name', align: 'center'},
                {title: '档案分类', field: 'type_name', align: 'center'},
                {title: '档案名称', field: 'file_name', align: 'center'},
                {title: '区号', field: 'area_code', align: 'center'},
                {
                    title: '档案状态', field: 'status', align: 'center', templet: function (d) {
                        if (d.status === 0) {
                            return '<span style="color: #398FFF;">在库</span>';
                        } else if (d.status === 1) {
                            return '<span style="color: #FF9200 ;">出库</span>';
                        } else if (d.status === 2) {
                            return '<span style="color: #398FFF;">出库未取走</span>';
                        } else if (d.status === 3) {
                            return '<span style="color: #FF9200;">归还未入库</span>';
                        }

                    }
                },
                {title: '用户名', field: 'user_name', align: 'center'},
                {title: '创建时间', field: 'create_time', align: 'center', width: 160},
                {title: '操作', toolbar: '#archivesTableBar', align: 'center', width: 230}
            ]
        ]
        tableIns = table.render({
            elem: '#archivesTable',
            url: '/archives/list',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            id: 'archivesTable',
            limits: [10, 20, 30, 50, 100, 200, 500],
            //解决页码的问题
            done: function (res) {
                // 获得当前页码
                var brforeCurr = tableIns.config.page.curr;
                // 获得当前页的记录数
                var dataLength = table.cache['archivesTable'].length;
                var count = res.count; // 获得总记录数
                //如果当前页的记录数为0并且总记录数不为0
                if (dataLength === 0 && count !== 0) {
                    // 刷新表格到上一页
                    table.reload("archivesTable", {
                        page: {
                            curr: brforeCurr - 1
                        }
                    });
                }
            }
        });

        table.on('tool(archivesTable)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            } else if (obj.event === 'more') {
                // 更多 - 下拉菜单
                let data = null;
                if (sysType != 2) {
                    data = [{
                        title: '查看',
                        id: 'detail'
                    }, {
                        title: '查看电子档案',
                        id: 'electronicArchives'
                    }];
                } else {
                    data = [{
                        title: '查看',
                        id: 'detail'
                    }, {
                        title: '查看子档案',
                        id: 'subFile'
                    }, {
                        title: '查看电子档案',
                        id: 'electronicArchives'
                    }];
                }
                dropdown.render({
                    elem: this, // 触发事件的 DOM 对象
                    show: true, // 外部事件触发即显示
                    data: data,
                    click: function (menudata) {
                        if (menudata.id === 'detail') {
                            window.info(obj);
                        } else if (menudata.id === 'subFile') {
                            // let curr = obj.config.page.curr;
                            // console.log(curr)
                            // 打开子档案列表
                            location.href = "/archives/subname/index?archivesId=" + obj.data.id;
                        } else if (menudata.id === 'electronicArchives') {
                            window.electronicArchives(obj);
                        }
                    },
                    align: 'right', // 右对齐弹出
                    style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' // 设置额外样式
                });
            }
        });
        // 查看电子档案
        window.electronicArchives = function (obj) {
            console.log(obj.data);
            parent.layer.open({
                type: 2,
                skin: 'layui-layer-radius', // 自定义一个CSS类名来设置边框圆角
                title: '查看电子档案',
                shadeClose: true,
                maxmin: true, //开启最大化最小化按钮
                area: ['70%', '800px'],
                move: false,
                content: '/electron/archives/table?archivesId=' + obj.data.id,
            });
        }


        window.info = function (obj) {
            parent.layer.open({
                title: ['档案详情', 'font-size: 18px;'],
                type: 2,
                offset: 'r',
                anim: 'slideLeft',
                area: ['40%', '100%'],
                shade: 0.5,
                shadeClose: true,
                maxmin: true,
                id: 'addNewEquipment',
                content: '/archives/info/view?archiveId=' + obj.data.id,
                move: false,
                end: function () {
                    table.reload('archivesTable');
                }
            });
        }

        table.on('toolbar(archivesTable)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
        });

        form.on('submit(search-query)', function (data) {
            if (checkTable === 1) {
                table.reload('archivesTable', {
                    where: data.field,
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    }
                });
            } else if (checkTable === 2) {
                table.reload('borrowingTable', {
                    where: data.field,
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    }
                });
            }
            return false;
        });

        window.remove = function (obj) {
            layer.confirm('<div>确定要删除&nbsp;&nbsp;<span style="color: #FF9200;">' + obj.data.file_name + '</span>&nbsp;&nbsp;档案吗?</div>', {
                icon: 3,
                title: ['删除确认', 'font-size: 18px;'],
                shade: 0.5,
                area: ['499px', '303px'],
                id: "borrowingConfirm"
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: "/archives/delete/save/" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code === 200) {
                            layer.msg(result.message, {
                                icon: 1,
                                time: 1800
                            }, function () {
                                obj.del();
                                table.reload("archivesTable");
                            });
                        } else {
                            layer.msg(result.message, {
                                icon: 2,
                                time: 3000
                            });
                        }
                    }
                })
            });
        }
        // 档案修改
        window.edit = function (obj) {
            layer.confirm('<div>确定要修改&nbsp;&nbsp;<span style="color: #FF9200;">' + obj.data.file_name + '</span>&nbsp;&nbsp;档案吗?</div>', {
                icon: 3,
                title: ['修改确认', 'font-size: 18px;'],
                shade: 0.5,
                area: ['499px', '303px'],
                id: "borrowingConfirm"
            }, function (index) {
                layer.close(index);
                parent.layer.open({
                    title: ['修改档案', 'font-size: 18px;'],
                    type: 2,
                    offset: 'r',
                    anim: 'slideLeft', // 从右往左
                    area: ['40%', '100%'],
                    shade: 0.5,
                    maxmin: true,
                    id: 'addNewEquipment',
                    content: '/archives/edit/' + obj.data.id,
                    move: false,
                    end: function () {
                        table.reload('archivesTable');
                    }
                });
            });
        }
        window.refresh = function (param) {
            table.reload('archivesTable');
        }
        // 借阅管理
        let borrowingCols = [
            [
                {type: 'checkbox'},
                {title: '档案id', field: 'file_id', align: 'center'},
                {title: '档案区域', field: 'area_name', align: 'center'},
                {title: '档案分类', field: 'type_name', align: 'center'},
                {title: '档案名称', field: 'file_name', align: 'center'},
                {title: '区号', field: 'area_code', align: 'center'},
                {
                    title: '档案状态', field: 'status', align: 'center', templet: function (d) {
                        if (d.status === 0) {
                            return '<span style="color: #398FFF;">在库</span>';
                        } else if (d.status === 1) {
                            return '<span style="color: #FF9200 ;">出库</span>';
                        } else if (d.status === 2) {
                            return '<span style="color: #398FFF;">出库未取走</span>';
                        } else if (d.status === 3) {
                            return '<span style="color: #FF9200;">归还未入库</span>';
                        }

                    }
                },
                {title: '用户名', field: 'user_name', align: 'center'},
                {title: '创建时间', field: 'create_time', align: 'center', width: 160},
                {
                    title: '操作', align: 'center', width: 280, templet: function (d) {
                        let html = '<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="info">详情</button>';
                        if (d.status === 0) {
                            html += '<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="takeOut">取出</button>';
                        } else {
                            html += '<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="return">归还</button>';
                        }
                        if (sysType == 2) {
                            html += '<button style="background-color: #2DBBF0 !important;border: 1px solid #2DBBF0 !important;" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="archivesSubname">查看子档案</button>';
                        }
                        html += '<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove">删除</button>';
                        return html;
                    }
                }
            ]
        ]
        borrowingIns = table.render({
            elem: '#borrowingTable',
            url: '/archives/list',
            page: true,
            cols: borrowingCols,
            skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            id: 'borrowingTable',
            //解决页码的问题
            done: function (res) {
                // 获得当前页码
                var brforeCurr = borrowingIns.config.page.curr;
                // 获得当前页的记录数
                var dataLength = table.cache['borrowingTable'].length;
                var count = res.count; // 获得总记录数
                //如果当前页的记录数为0并且总记录数不为0
                if (dataLength === 0 && count !== 0) {
                    // 刷新表格到上一页
                    table.reload("borrowingTable", {
                        page: {
                            curr: brforeCurr - 1
                        }
                    });
                }
            }
        });
        table.on('toolbar(borrowingTable)', function (obj) {
            if (obj.event === 'refresh') {
                table.reload('borrowingTable');
            }
        });

        table.on('tool(borrowingTable)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'takeOut') {
                window.takeOut(obj);
            } else if (obj.event === 'return') {
                window.return(obj);
            } else if (obj.event === 'info') {
                window.info(obj);
            } else if (obj.event === 'archivesSubname') {
                // 查看子档案
                location.href = "/archives/subname/borrowing/index?archivesId=" + obj.data.id;
            }
        });

        window.takeOut = function (obj) {
            layer.confirm('<div>确定要取出&nbsp;&nbsp;<span style="color: #FF9200;">' + obj.data.file_name + '</span>&nbsp;&nbsp;档案吗?</div>', {
                icon: 3,
                title: ['取出确认', 'font-size: 18px;'],
                shade: 0.5,
                area: ['499px', '303px'],
                id: "borrowingConfirm"
            }, function (index) {
                layer.close(index);
                parent.layer.open({
                    title: ['取出档案', 'font-size: 18px;'],
                    type: 2,
                    offset: 'r',
                    anim: 'slideLeft', // 从右往左
                    area: ['40%', '100%'],
                    shade: 0.5,
                    maxmin: true,
                    id: 'addNewEquipment',
                    content: '/archives/takeout/view?archiveId=' + obj.data.id,
                    move: false,
                    end: function () {
                        table.reload('borrowingTable');
                    }
                });
            });
        }

        window.return = function (obj) {
            layer.confirm('<div>确定要归还&nbsp;&nbsp;<span style="color: #FF9200;">' + obj.data.file_name + '</span>&nbsp;&nbsp;档案吗?</div>', {
                icon: 3,
                title: ['归还确认', 'font-size: 18px;'],
                shade: 0.5,
                area: ['499px', '303px'],
                id: "borrowingConfirm"
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: '/archives/return/save',
                    data: JSON.stringify({"archiveId": obj.data.id}),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code === 200) {
                            layer.msg(result.message, {icon: 1, time: 1800}, function () {
                                table.reload('borrowingTable');
                            });
                        } else {
                            layer.msg(result.message, {icon: 2, time: 3000});
                        }
                    }
                })
            });
        }
    })
</script>
</body>
</html>
